﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif 

// **********************************************************************
// Copyright (C) XM
// Author: 赵思佳
// Date: 2019-01-16
// Desc: 
// **********************************************************************
namespace SpaceDFramework
{
    public class ResolutionCheck
    {
        public enum Device
        {
            Other,//其他奇怪的分辨率
            Phone,//手机
            iPhone,//苹果
            iPhoneX,//苹果X
            Pad,//平板
        }
        /// <summary>
        /// 判断是横屏还是竖屏
        /// </summary>
        /// <returns>是不是横屏</returns>
        public static bool GetIsLandscape()
        {
            var isLandscape = Screen.width > Screen.height;

            return isLandscape;
        }
        /// <summary>
        /// 得到设备宽高比
        /// </summary>
        /// <returns>宽高比</returns>
        public static float getRadio()
        {
            var isLandscape = GetIsLandscape();
            float radio = isLandscape ? (float)Screen.width / Screen.height : (float)Screen.height / Screen.width;
            return radio;
        }
        /// <summary>
        /// 判断设备是不是平板
        /// </summary>
        /// <returns>是不是平板</returns>
        public static bool isPad()
        {
            float radio = getRadio();
            return inRadioRange(radio, 4f / 3 - 0.05f, 4f / 3 + 0.05f);
        }
        /// <summary>
        /// 判断是不是iphone设备
        /// </summary>
        /// <returns>是否iphone</returns>
        public static bool isiPhone()
        {
            float radio = getRadio();
            return inRadioRange(radio, 3f / 2 - 0.05f, 3f / 2 + 0.05f);
        }
        /// <summary>
        /// 普通设备分辨率为16:9
        /// </summary>
        /// <returns>是否普通手机设备</returns>
        public static bool isPhone()
        {
            float radio = getRadio();
            return inRadioRange(radio, 16f / 9 - 0.05f, 16f / 9 + 0.05f);
        }
        /// <summary>
        /// 判断是否iphoneX设备
        /// </summary>
        /// <returns>是否iphoneX设备</returns>
        public static bool isiPhoneX()
        {
            float radio = getRadio();
            return inRadioRange(radio, 2436f / 1125 - 0.05f, 2436f / 1125 + 0.05f);
        }
        /// <summary>
        /// 判断是否在分辨率范围内的函数
        /// </summary>
        /// <param name="radio">宽高比</param>
        /// <param name="min">宽高比最小值</param>
        /// <param name="max">宽高比最大值</param>
        /// <returns>返回是否在分辨率范围内</returns>
        public static bool inRadioRange(float radio, float min, float max)
        {
            if (radio > min && radio < max)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 判断设备类型
        /// </summary>
        /// <returns>设备类型</returns>
        public static Device JudgeDevice()
        {
            if (isPhone())
                return Device.Phone;
            else if (isiPhone())
                return Device.iPhone;
            else if (isiPhoneX())
                return Device.iPhoneX;
            else if (isPad())
                return Device.Pad;
            else
                return Device.Other;
        }
    }
}
